<?php
$wid = Session::get('wid');
$is_yg = Session::get('is_yg', 0);
$userAgency = (new Model('user_agency'))->find(['isadmin'=>1]);
$indexList = array(
 
    '概况总览' => array(
    'name'  => '概况总览',
    'style' => '<i class="font_family theicon icon-gaikuang_xuanzhong"></i>',
    'id'    => 'm14',
    'sub'   => array(

      array(
        'name' => '概况总览',
        'file' => 'Addons/QyWechat/Admin/Datas/statistics',
      ),
    ),
  ),
       '引流获客' => array(
    'name'  => '引流获客',
    'style' => '<i class="font_family theicon icon-neirongshichang"></i>',
    'id'    => 'm14',
    'sub'   => array(

      array(
        'name' => '渠道活码', 
        'file' => 'Addons/QyWechat/Admin/Externalcontact/contact_way',
      ),
      array(
        'name' => '裂变任务',
        'file' => 'Addons/Fission/Admin/Fission/mission_list',
      ),
      // array(
      //   'name' => '群裂变',
      //   'file' => 'Addons/QunFission/Admin/QunFission/mission_list',
      // ),
       array(
        'name' => '进群宝',   
        'file' => 'Addons/Inqunbao/Admin/Inqunbao/mission_list',
      ),
	  array(
        'name' => '批量加好友',
        'file' => 'Addons/BatchAddFriends/Admin/Mission/mission_list',
      ),
     array(
        'name' => '红包获客',
        'file' => 'Addons/Redguest/Admin/Envelopes/index',
      ),
    ),
  ),
          '客户联系' => array(
    'name'  => '客户联系',
    'style' => '<i class="fa fa-user icon"></i>',
    'id'    => 'm14',
    'sub'   => array(

      array(
        'name' => '客户管理',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/customer_list',
      ),
	        array(
        'name' => '消息群发',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/msg_template',
      ),
      array(
        'name' => '客户标签',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/tag_manage',
      ),
	    array(
        'name' => '流失客户',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/del_follow_user_record',
      ),
	    array(
    		'name' => '历史朋友圈',
    		'file' => 'Addons/Moments/Admin/Moments/pyq',
	    ),
      array(
        'name' => '欢迎语',
        'file' => 'Addons/QyWechat/Admin/Users/welcome_msg',
      ),

	      /**array(
        'name' => '快捷回复',
        'file' => 'Addons/QyWechat/Admin/Reply/quick_reply',
      ),*/
	  	  array(
        'name' => '企微助手',
        'file' => 'Addons/QyWechat/Admin/MessageSend/message_send_set',
      ),
        array(
        'name' => '违规词提醒',
        'file' => 'Addons/QyWechat/Admin/MarketingTools/violation_remind_list',
      ),
      array(
        'name' => '互动雷达',
        'file' => 'Addons/InteractiveRadar/Admin/Radar/radar_list',、
      ),
      array(
          'name' => '互动红包',
          'file' => 'Addons/Redenvelopes/Admin/Envelopes/index.html',
      ),
      array(
          'name' => '客户阶段',
          'file' => 'Addons/CusManage/Admin/CusManage/clmanage',
      ),  
      array(
          'name' => '个人SOP',
          'file' => 'Addons/PersonageSop/Admin/Sop/index',
      ),  
      array(
          'name' => '朋友圈展示',
          'file' => 'Addons/Friend/Admin/Friend/pyq',
      ),

      array(
          'name' => '素材库',
          'file' => 'Addons/Materiallibrary/Admin/Material/authorizer_list',
      ),
      array(
          'name' => '短信群发',
          'file' => 'Addons/Sms/Admin/Sms/index',
      ),
      array(
          'name' => '自定义信息',
          'file' => 'Addons/UserMessageSet/Admin/Messageset/index',
      ),
      array(
          'name' => '自动打标签',
          'file' => 'Addons/AutomaticLabe/Admin/AutomaticLabe/index',
      ),
    ),
  ),
            '群运营' => array(
    'name'  => '群运营',
    'style' => '<i class="fa fa-bars icon"></i>',
    'id'    => 'm14',
    'sub'   => array(
      array(
        'name' => '消息群发',
        'file' => 'Addons/QyWechat/Admin/MarketingTools/group_send_manage',
      ),
	 array(
        'name' => '自动拉群',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/auto_pull_group',
      ),
      array(
        'name' => '群列表',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/groupchat_list',
      ),
      array(
        'name' => '群数据',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/user_creat_groupchat_statistic',
      ),
	  	 array(
        'name' => '客户群提醒',
        'file' => 'Addons/QyWechat/Admin/MarketingTools/group_remind_list',
      ),
	  	 array(
        'name' => '欢迎语',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/group_welcome_template',
      ),
	  	  array(
        'name' => '标签建群',
        'file' => 'Addons/QyWechat/Admin/MarketingTools/tag_group_list',
      ),
      array(
          'name' => '群SOP',
          'file' => 'Addons/Groupsop/Admin/Sop/index',
      ), 
      array(
        'name' => '群数据统计',
        'file' => 'Addons/QyWechat/Admin/GroupChatStatistic/index',
      ),
      array(
        'name' => '群标签',
        'file' => 'Addons/QyWechat/Admin/GroupChatTag/index',
      ),
    ),
  ),
  
  '侧边栏' => array(
    'name'  => '侧边栏',
    'style' => '<i class="fa fa-window-restore icon"></i>',
    'id'    => 'm10',
    'sub'   => array(

      array(
        'name' => '应用配置',
        'file' => 'Addons/QyWechat/Admin/Reply/quick_reply_steps',
      ),
      array(
        'name' => '快捷回复',
        'file' => 'Addons/QyWechat/Admin/Reply/quick_reply',
      ),
       array(
	   'name' => '客户画像',
	   'file' => 'Addons/CustomerPortrait/Admin/Portrait',
		 ),
		  array(
	   'name' => '一客一码',
	   'file' => 'Addons/CustomerQrcode/Admin/CustomerQrcode/qrcode_list',
     ),
     array(
      'name' => '运营工具',
      'file' => 'Addons/Operationaltools/Admin/Operational',
      ),
     array(
      'name' => '第三方订单',
      'file' => 'Addons/OrderManager/Admin/OrderManager/index',
      ),

    ),
  ),

   '企业管理' => array(
    'name'  => '企微管理',
    'style' => '<i class="fa fa-comment-o icon"></i>',
    'id'    => 'm10',
    'sub'   => array(

      array(
        'name' => '企微设置',
        'file' => 'Addons/QyWechat/Admin/QyWechat/qy_set',
      ),
      array(
        'name' => '通讯录',
        'file' => 'Addons/QyWechat/Admin/Users/user_list',
      ),
       array(
	   'name' => '会话存档',
	   'file' => 'Addons/QyChatData/Admin/ChatData/chat_data',
		 ),
       array(
        'name' => '版权设置',
        'file' => 'Addons/QyWechat/Admin/QyWechat/copyright',
      ),
       array(
        'name' => '成员统计',
        'file' => 'Addons/QyWechat/Admin/Data/index',
      ),
       array(
        'name' => '授权管理',
        'file' => 'Addons/WechatOpenPlatform/Admin/ReceiveTicke/platform',
      ),

	     /** array(
        'name' => '侧边栏',
        'file' => 'Addons/QyWechat/Admin/Reply/quick_reply_steps',
      ),*/
    ),
  ),
  '账户管理'  => array(
    'name'  => '账户管理',
    'style' => '<i class="fa  fa-home icon"></i>',
    'id'    => 'm2',
    'sub'   => array(
      array(
        'name' => '账户中心',
        'file' => 'userCenter/balance',
      ),
      array(
        'name' => '子账户',
        'file' => 'yg/list',
      ),

    ),
  ),


);

$dir = DOXCX_FRAME_PATH.'controller/admin/menu';
$fileList=getFileList($dir);
foreach($fileList as $value){
	include $dir.'/'.$value;
}

$fileList=getAddonsFileList('menu');
// 读取模块配置文件
foreach($fileList as $value){
    $arr=include($value);
    // $indexList=array_replace_recursive($indexList,(array)$arr['menu']);
    if((array)$arr['menu']){
      foreach ((array)$arr['menu'] as $key => $mune) {
        if(array_key_exists($key, $indexList)){
          $indexList[$key]['sub'] = array_merge($indexList[$key]['sub'],$mune['sub']);
        }else{
          $indexList[$key] = $mune;
        }
      }
    }
}

$agency=get_user_agency();
$userMenu = (new Model('user_menu'))->find(['pid'=>$agency->id]);
if(!$userMenu->id){
	$userMenu = (new Model('user_menu'))->find(['pid'=>$userAgency->id]);
}
$menusort=json_decode($userMenu->menusort,1);
$menuname=json_decode($userMenu->menuname,1);
if($userMenu->id){
	foreach($indexList as $k=>$m){
    if(!array_key_exists($k, $menusort)){ 
      $menusort[$k] = max($menusort) + 1;
      $userMenu->menusort = json_encode($menusort,320);
      $userMenu->save();
    } 
    $indexList[$k]['id']=$menusort[$k];
		if($menuname[$k]){
			$indexList[$k]['name']=$menuname[$k];
		}
	}
	if(count($menusort)){
		array_multisort(array_column($indexList,'id'),SORT_ASC,$indexList);
	}
}

if ($is_yg != 1) {
  // 非员工
  $index = $indexList;
} else {
  // 员工
  $yg_id = Session::get('yg_id', 0);
  $yg = (new Model('yg'))->find(['wid' => $wid, 'id' => $yg_id]);
  if (!$yg_id || !$yg->id) {
    Redirect::to('/logout');
  } else {
    $authority=json_decode($yg->authority,true);
    $index=[];
    foreach ($authority as $a) {
      if(array_key_exists($a, $indexList)){
        $index[]=$indexList[$a];
      }
    }
  }
}

return [
  $indexList,
  $index,
];